home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2 Examples.sit / Raven 1.2 Examples / BoxPaint / Source / Main.cpp < prev    next >
C/C++ Source or Header  |  1997-09-04  |  5KB  |  194 lines

  1. /*
  2.  *  File:       Main.cpp
  3.  *  Summary:       The big enchilada.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996 Jesse Jones. All Rights Reserved.
  7.  *
  8.  *  Change History (most recent first):    
  9.  *
  10.  *         <->     2/24/96    JDJ        Created.
  11.  */
  12.  
  13. #include <List.h>
  14.  
  15. #include <List.h>
  16.  
  17. #include <Z3DUtils.h>
  18. #include <ZAppBootStrap.h>
  19. #include <ZFloatingDesktop.h>
  20. #include <ZGestalt.h>
  21. #include <ZMiscUtils.h>
  22. #include <ZPreferences.h>
  23. #include <ZRegularDesktop.h>
  24. #include <ZStringUtils.h>
  25.  
  26. #if RAVEN_OPERATOR_NEW
  27. #include <ZBestFitAllocator.h>
  28. #include <ZMemoryHeap.h>
  29. #include <ZNewAndDelete.h>
  30. #include <ZSimpleAllocator.h>
  31. #endif
  32.  
  33. #include "App.h"
  34.  
  35.  
  36. // ===================================================================================
  37. //    class TBootStrap
  38. // ===================================================================================
  39.  
  40. //---------------------------------------------------------------
  41. //
  42. // TBootStrap::DoEarlyInit
  43. //
  44. // This is called after the toolbox is initialized, but before
  45. // static objects are constructed. You shouldn't have to do
  46. // anything besides creating the object heap here. (Use OnBoot
  47. // if you need to initialize other things).
  48. //
  49. //---------------------------------------------------------------
  50. void TBootStrap::DoEarlyInit()
  51. {
  52.     const long  kInitialObjectHeapSize   = 500*1024L;        // ・・・ハadjust these numbers
  53.     const long  kObjectHeapIncrementSize = 32*1024L;        
  54.     const short    kNumMasterPtrBlocks      = 10;
  55.  
  56.     for (short i = 1; i <= kNumMasterPtrBlocks; i++)
  57.         MoreMasters();
  58.  
  59. #if RAVEN_OPERATOR_NEW                                    // on by default
  60.     ASSERT(gObjectHeap == nil);
  61.     
  62.     TAllocator* alloc = new TSimpleAllocator(kInitialObjectHeapSize, kObjectHeapIncrementSize);
  63.     gObjectHeap = new TMemoryHeap(alloc);
  64.  
  65. #else
  66.     _prealloc_newpool(kInitialObjectHeapSize);
  67.     _set_newpoolsize(kObjectHeapIncrementSize);
  68.     _set_newnonptrmax(kObjectHeapIncrementSize/4);
  69. #endif
  70. }
  71.  
  72. #pragma mark -
  73.  
  74. // ===================================================================================
  75. //    class CMyBooter
  76. //        TAppBootStrap initializes some of the core Raven classes and checks to make
  77. //        sure the machine is capable of running your app.
  78. // ===================================================================================
  79. class CMyBooter : public TAppBootStrap {
  80.     
  81.     typedef TAppBootStrap Inherited;
  82.     
  83. //-----------------------------------
  84. //    Initialization/Destruction
  85. //
  86. public:
  87.     virtual             ~CMyBooter();
  88.     
  89.                           CMyBooter();
  90.  
  91. //-----------------------------------
  92. //    Inherited API
  93. //
  94. protected:
  95.     virtual void         OnSystemNeeds(list<string, allocator<string> >& needs);
  96.  
  97.     virtual void         OnBoot();
  98. };
  99.  
  100.  
  101. //---------------------------------------------------------------
  102. //
  103. // CMyBooter::~CMyBooter
  104. //
  105. //---------------------------------------------------------------
  106. CMyBooter::~CMyBooter()
  107. {
  108.     Terminate3D();
  109. }
  110.  
  111.  
  112. //---------------------------------------------------------------
  113. //
  114. // CMyBooter::CMyBooter
  115. //
  116. //---------------------------------------------------------------
  117. CMyBooter::CMyBooter()
  118. {
  119.     mIdealDisplayMode = SDisplayMode(640, 480, 32);        // QuickDraw 3D works best in direct color    
  120.  
  121. #if !DEBUG
  122.     mCanChangeDevice = true;
  123. #endif
  124. }
  125.  
  126.  
  127. //---------------------------------------------------------------
  128. //
  129. // CMyBooter::OnSystemNeeds
  130. //
  131. // If your app requires things that aren't on every machine (eg
  132. // QuickDraw 3D, the Drag Manager, etc) add a test here. TBootStrap
  133. // will popup a dialog listing all of the items that are missing
  134. // from the user's machine.
  135. //
  136. //---------------------------------------------------------------
  137. void CMyBooter::OnSystemNeeds(list<string, allocator<string> >& needs)
  138. {
  139.     Inherited::OnSystemNeeds(needs);
  140.  
  141.     if (!UGestalt::hasQuickDraw3D)
  142.         needs.push_back("QuickDraw 3D");
  143.         
  144. }
  145.  
  146.  
  147. //---------------------------------------------------------------
  148. //
  149. // CMyBooter::OnBoot
  150. //
  151. // This is the best place to initialize stuff.
  152. //
  153. //---------------------------------------------------------------
  154. void CMyBooter::OnBoot()
  155. {
  156.     Inherited::OnBoot();
  157.  
  158.     // Aplications often have just a few block sizes that account
  159.     // for the bulk of their operator new allocations. You can 
  160.     // speed up operator new by calling AddAllocator for these
  161.     // common sizes. (You can find the most used block sizes by
  162.     // using the "Dump Object Heap" command in the Debug menu).
  163.     gObjectHeap->AddAllocator(20, 400);
  164.  
  165.     TFloatingDesktop::Init();                            
  166.  
  167.     if (!Init3D()) {
  168.         ReportError(LoadAppString("Couldn't startup!"), LoadAppString("Failed to initialize QuickDraw 3D."));
  169.         ExitToShell();
  170.     }
  171.  
  172.     UPreferences::Init("BoxPaint Prefs", 'SKEL');
  173. }
  174.  
  175. #pragma mark -
  176.  
  177. //---------------------------------------------------------------
  178. //
  179. // Main
  180. //
  181. //---------------------------------------------------------------
  182. void main()
  183. {
  184.     CMyBooter booter;
  185.     booter.Boot();
  186.             
  187.     {
  188.     CApplication theApp;
  189.         theApp.Run();                    
  190.     }
  191. }
  192.  
  193.  
  194.